import { IManagement } from "@/api";
import { Button, Switch } from "@/components";
import { FormItem } from "@/components/SearchForm/formTypes";
import { INDEX_COLUMN, OPERATE_COLUMN } from "@/config";
import { RATE_LIST, TASK_STATUS } from "@/constants";
import { OptionsUtil } from "@/utils";
import { Space } from "antd";
import { ColumnsType } from "antd/es/table";
export const getFields = (): FormItem[] => [
  {
    type: "Input",
    formItemProps: {
      name: "name",
      label: `任务名称`,
    },
  },
  {
    type: "Select",
    formItemProps: {
      name: "state",
      label: "状态",
      initialValue: "",
    },
    props: {
      options: OptionsUtil.getSimpleData(TASK_STATUS),
    },
  },
];
export const getColumns = (
  onOpen: FcProps,
  onCheckModalOpen: FcProps,
  jumpToRecord: FcProps,
  onBatchUpdate: FcProps,
  onStart:FcProps,
): ColumnsType<IManagement.ResManagementItem> => [
  {
    key: INDEX_COLUMN,
    title: "序号",
    render: (value, record, index) => index + 1,
    width: 70,
  },
  {
    title: "任务名称",
    dataIndex: "name",
    ellipsis: true,
  },
  {
    title: "任务描述",
    dataIndex: "desc",
  },
  {
    title: "状态",
    dataIndex: "state",
    render(value, record, index) {
      return (
        <Switch
          checked={record.state === 1}
          onChange={(val) => onBatchUpdate({ state: val, ids: [record.id] })}
        />
      );
    },
  },
  {
    key: "cycle",
    title: "上报间隔",
    render(value, { cycle, rate }, index) {
      return `${cycle}${RATE_LIST.find((item) => item.value === rate)?.label}`;
    },
    width: 100,
  },
  {
    title: "更新时间",
    dataIndex: "updateTime",
  },
  {
    key: OPERATE_COLUMN,
    title: "操作",
    fixed: "right",
    width: 70,
    render(value, record, index) {
      return (
        <Space>
          <Button type="link" onClick={() => onCheckModalOpen(record)}>
            查看
          </Button>
          <Button
            type="link"
            onClick={() => {
              onOpen(record);
            }}
          >
            编辑
          </Button>
          <Button
              type="link"
              onClick={() => {
                  onStart(record);
              }}
          >
            立即执行
          </Button>
          <Button
            type="link"
            onClick={() => {
              // &taskName=${record.taskName}
              jumpToRecord(
                `/record?flag=report&taskKey=${record.taskKey}`
              );
            }}
          >
            上报记录
          </Button>
          <Button
            type="link"
            onClick={() => {
              jumpToRecord(
                `/record?flag=unReport&taskKey=${record.taskKey}`
              );
            }}
          >
            未上报记录
          </Button>
        </Space>
      );
    },
  },
];
